package rui.game.component;

import lombok.Setter;
import rui.game.Chunk;

import javax.swing.*;
import java.awt.*;
import java.util.List;

/**
 * @author 赵睿
 */
public class Center extends JPanel {
    @Setter
    private LayoutManager layoutManager;

    @Setter
    private GamePanel gamePanel;

    public Center(GamePanel gamePanel) {
        this.gamePanel = gamePanel;
    }

    public static Center init(Center center,GamePanel gamePanel,GameFrame gameFrame){
        if(center==null){
            center = new Center(gamePanel);
            center.init();
            gameFrame.getContentPane().add(center);
        }
        return center;
    }

    public void init(){
        globalSettings();
        layoutSettings();
        this.setLayout(layoutManager);
        gamePanel.toList().forEach(this::add);
    }

    protected void globalSettings(){
        this.setLocation(40, 80);
        this.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.black));
        this.setSize(320, 320);
        this.setBackground(SystemColor.textText);
    }

    protected void layoutSettings(){
        if(layoutManager!=null){
            return ;
        }
        //网格化
        layoutManager =new GridLayout(4, 4);
    }
}
